<?php

namespace App\Admin\Controllers;

use App\Http\Controllers\Controller;
use Encore\Admin\Controllers\ModelForm;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Layout\Content;
use App\Models\InformationReservation;

class InformationReservationController extends Controller
{
  use ModelForm;
  public function index()
  {
      return Admin::content(function (Content $content) {
          $content->header('资讯预约');
          $content->description('管理');
          $content->body($this->grid());
      });
  }

  public function edit($id)
  {
      return Admin::content(function (Content $content) use ($id) {
          $content->header('资讯预约');
          $content->description('编辑');

          $content->body($this->form()->edit($id));
      });
  }

  public function create()
  {
      return Admin::content(function (Content $content) {
          $content->header('资讯预约');
          $content->description('创建');

          $content->body($this->form());
      });
  }

  protected function grid()
  {
      return Admin::grid(InformationReservation::class, function (Grid $grid) {
          // $grid->position_tags('轮播图序号');
          $grid->id('序号');
          $grid->name('预约者姓名');
          $grid->phone_number('预约者手机号');
          $grid->service_time('预约的服务时间');
          $grid->content('预约内容');
          $grid->user_id('预约者id');
          $grid->disableFilter();
          $grid->disableExport();
          // $grid->disableCreateButton();
          // $grid->disablePagination();
          $grid->disableFilter();
          $grid->paginate(10);
          $grid->perPages([10,20,30]);
          $grid->disableRowSelector();
          $grid->disableCreateButton();
          // $grid->disableActions();
          $grid->actions(function ($actions) {
              $actions->disableEdit();//禁止修改
              // $actions->disableDelete();//禁止删除
          });
      });
  }

  protected function form()
  {
      return Admin::form(InformationReservation::class, function (Form $form) {
          $form->text('name', '预约者姓名');
          $form->text('phone_number', '预约者手机号');
          $form->datetime('service_time', '预约的服务时间');
          $form->text('content', '预约内容');
          $form->text('user_id', '预约者id');
      });
  }
  }
